package com.caac.core.service.impl;

import java.util.List;

import com.caac.core.dao.PageCounterDao;
import com.caac.core.dm.PageCounter;
import com.caac.core.service.PageCounterManager;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright caac 2004</p>
 * <p>Company: caac</p>
 * @author <a href="mailto:project@caac.com.cn">Project Group</a>
 * @version 1.0
 */

public class PageCounterManagerImpl extends BaseManagerImpl implements
        PageCounterManager {
    private PageCounterDao pageCounterDao;

    public void setPageCounterDao(PageCounterDao pageCounterDao) {
        this.pageCounterDao = pageCounterDao;
    }

    public int getSumPageCounter() {
        return pageCounterDao.getSumPageCounter();
    }

    public List getAllPageCounters() {
        return pageCounterDao.getAllPageCounters();
    }

    public void savePageCounter(String servletPath) {
        String coverPath = servletPath.substring(0,
                                                 servletPath.indexOf(".jsp") +
                                                 4);
        PageCounter counter = pageCounterDao.getPageCounter(coverPath);
        if (counter == null) {
            counter = new PageCounter();
            counter.setServletPath(coverPath);
            counter.setCounter(new Integer(1));
        } else {
            counter.setCounter(new Integer(counter.getCounter().intValue() + 1));
        }
        pageCounterDao.savePageCounter(counter);

        //pageCounterDao.savePageCounter(coverPath);
    }

}
